home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / p4 / p4-1_2a.lha / p4-1.2a / doc / p4.txt < prev    next >
Text File  |  1992-11-07  |  78KB  |  2,219 lines

  1.  
  2.  
  3.  
  4.  
  5.           User's Guide to the p4 Parallel Programming System
  6.  
  7.              Ralph Butler and Ewing Lusk
  8.  
  9.              Argonne National Laboratory
  10.  
  11.  
  12.  
  13. Introduction
  14. ============
  15.  
  16.  
  17. P4 is a library of macros and subroutines developed at Argonne National
  18. Laboratory for programming a variety of parallel machines.  Its
  19. predecessor was the m4-based "Argonne macros" system described in the
  20. Holt, Rinehart, and Winston book {Portable Programs for Parallel
  21. Processors}, by Lusk, Overbeek, et al., from which p4 takes its
  22. name[lusk-overbeek:p4-book].  The current p4 system maintains the
  23. same basic computational models described there (monitors for the
  24. shared-memory model, message-passing for the distributed-memory model,
  25. and support for combining the two models) while significantly increasing
  26. ease and flexibility of use. *Note Getting Started:: for a simple example.
  27.  
  28. P4 is intended to be portable, simple to install and use, and efficient.  It
  29. can be used to program networks of workstations, advanced parallel
  30. supercomputers like the Intel Touchstone Delta and the Alliant Campus
  31. HiPPI-based system, and single shared-memory multiprocessors.  It has
  32. currently been installed on the following list of machines: Sequent Symmetry
  33. (Dynix and PTX), Encore Multimax, Alliant FX/8, FX/800, and FX/2800, Cray
  34. X/MP, Sun, NeXT, DEC, Silicon Graphics, HP, and IBM RS6000 workstations,
  35. Stardent Titan, BBN GP-1000 and TC-2000, Intel IPSC/860, Intel Touchstone
  36. Delta, Alliant Campus, and Thinking Machines' CM-5.  It will soon be ported to
  37. to the Intel Paragon.  It is not difficult to port to new systems.  Although
  38. p4 tries to be completely portable, there are a small number of
  39. specific exceptions (*Note Machine-Specific Notes::) that may need to be taken
  40. into account on a given machine.
  41.  
  42. You can obtain the complete distribution of p4 by anonymous ftp from
  43. `info.mcs.anl.gov'.  Take the file `p4.tar.Z' from the
  44. directory `pub/p4'.  The distribution contains all source code,
  45. installation instructions, this reference manual, and a collection of
  46. examples in both C and Fortran. `Alog' is included in the
  47. distribution with p4.  The file `upshot.tar.Z' contains display
  48. facilities that can be used with p4 and other systems.
  49.  
  50. To ask questions about p4, report bugs, contribute examples, etc., you can
  51. send mail to `p4@mcs.anl.gov'.
  52.  
  53. The current release is version 1.2.  You can check which version of the source
  54. code you have by looking at the file `lib/p4_patchlevel.h' in the
  55. distribution.  You can check which version of the object code you have linked
  56. to by running any p4 program with the command-line option `-p4version'
  57. (*Note Command-Line Arguments::).
  58.  
  59. Salient features of the current release of p4 include: 
  60.    * `xdr' support for heterogeneous networks
  61.    * manual enhanced and converted to latex format
  62.    * Emacs info version of the manual for on-line help
  63.    * SYSV IPC support added for several machines (for shared-memory
  64.        multiprocessing on workstations that support multiple processors)
  65.    * instrumentation added for automatic logging/tracing
  66.    * automatic or user control of message-passing/buffer-management
  67.    * high-resolution clock support for several machines
  68.    * error/interrupt handling
  69.    * an optional secure server for quick startup
  70.  
  71.  
  72. A useful companion system is the `alog/upshot' logging and X-based trace
  73. examination facility.  (*Note Creating Logfiles for Upshot::.)
  74.  
  75.  
  76.  
  77. Structure of the Distribution Directory
  78. =======================================
  79.  
  80.  
  81.  
  82. The p4 source code distribution contains the following files and
  83. subdirectories:
  84.  
  85.  
  86. Makefile     
  87.       The makefile for making the p4 system, doing the installation,
  88.        and making makefiles for user applications.
  89. OPTIONS     
  90.       A file controlling various compile-time options, such as
  91.        whether System V shared-memory operations are to be enabled, whether system
  92.        debug message printing is to be enabled, and whether automatic
  93.        instrumentation of p4 operations for the `upshot' logging and tracing
  94.        program is to be done.
  95. README     
  96.       General instructions.
  97. alog     
  98.       Source code for the ALOG tracing package.
  99. bin     
  100.       Scripts for starting and killing servers, killing runaway p4
  101.        processes, merging `upshot' logfiles, and other useful utilities.
  102. contrib     
  103.       Examples contributed by p4 users.
  104. contrib_f     
  105.       Fortran examples contributed by users.
  106. doc     
  107.       The man page, together with this manual and supporting files.
  108. include     
  109.       The include directory for making p4 applications.  Most of
  110.        these are (hard) links into the `lib' directory.
  111. lib     
  112.       The source code for the p4 system.
  113. lib_f     
  114.       The Fortran interface for p4.  
  115. messages     
  116.       A basic set of message-passing examples in C.
  117. messages_f     
  118.       A basic set of message-passing examples in Fortran.
  119. monitors     
  120.       A basic set of shared-memory examples in C.
  121. servers     
  122.       The secure and insecure servers.
  123. usc     
  124.       The portable microsecond clock routines.
  125. util     
  126.       Assorted supporting files, particularly for making the p4
  127.        distribution. 
  128.  
  129.  
  130.  
  131.  
  132. Installing p4
  133. =============
  134.  
  135.  
  136.  
  137. In this section we describe how to install the p4 library, either for
  138. your own personal use or for the use of everyone at your site.  In the
  139. first case you do not need any super-user privileges.  In the second
  140. case, you may or may not, depending on how things are configured at
  141. your site.  We also describe how to install and run the examples that
  142. come with p4, the online help system (this manual as an emacs info-file)
  143. and how to build a working directory for your own programs yet share
  144. the installed copy of p4 with other users.
  145.  
  146.  
  147.  
  148. Installing the p4 System
  149. ------------------------
  150.  
  151.  
  152. To build p4, position yourself in the `p4' directory and type:
  153.      make all MACHINE=<machine>
  154.  
  155. where <machine> is one of the machine names listed in
  156. `p4/util/machines', currently:
  157.  
  158.  
  159. SUN     
  160.       Sun-3, Sun386i, Sparc-1, or Sparc-2 workstations
  161.      
  162. HP     
  163.       HP workstations
  164.      
  165. DEC5000     
  166.       Dec 5000 workstations
  167.      
  168. NEXT     
  169.       68030- or 68040-based NeXT workstations
  170.      
  171. RS6000     
  172.       IBM RS 6000 series workstations
  173.      
  174. IBM3090     
  175.       IBM 3090 running IBM's version of UNIX, AIX
  176.      
  177. BALANCE     
  178.       Sequent Symmetry shared-memory multiprocessor
  179.      
  180. SYMMETRY     
  181.       Sequent Symmetry shared-memory multiprocessor
  182.      
  183. SYMMETRY_PTX     
  184.       Sequent Symmetry shared-memory multiprocessor PTX OS
  185.      
  186. MULTIMAX     
  187.       Encore Multimax shared-memory multiprocessor
  188.      
  189. GP_1000     
  190.       BBN GP-1000
  191.      
  192. TC_2000     
  193.       BBN TC-2000
  194.      
  195. TC_2000_TCMP     
  196.       BBN TC-2000 with the TCMP message-passing library
  197.      
  198. IPSC860     
  199.       Intel IPSC/860 (nodes only)
  200.      
  201. IPSC860_SOCKETS     
  202.       Intel IPSC/860 with socket libraries on the nodes
  203.      
  204. DELTA     
  205.       Intel DELTA 
  206.      
  207. TITAN     
  208.       Stardent Titan
  209.      
  210. SGI     
  211.       Silicon Graphics workstations
  212.      
  213. CRAY     
  214.       Cray X/MP
  215.      
  216. FX8     
  217.       Alliant FX/8
  218.      
  219. FX2800     
  220.       Alliant FX/2800 or FX/800
  221.      
  222. FX2800_SWITCH     
  223.       Alliant FX/2800 or FX/800, with CAMPUS HiPPI switch
  224.      
  225. KSR     
  226.       Kendall Square KSR-1
  227.      
  228. CM-5     
  229.       Thinking Machines' CM-5
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236. For example:
  237.      make all MACHINE=SYMMETRY
  238.  
  239. The `all' is optional, for example
  240.      make MACHINE=SEQUENT
  241.  
  242. This will create a machine-dependent `Makefile' in each subdirectory,
  243. make the p4 library, and compile and link a subset of the examples.
  244.  
  245. To add a new machine type, or to change the characteristic parameters
  246. associated with an existing one, you can edit the file 
  247. `p4/util/defs.all'.
  248.  
  249. To save disk space, various intermediate object files can be removed with
  250.      make clean
  251.  
  252. The system can be restored to its original, machine-independent state with
  253.      make realclean
  254.  
  255. Note that this removes the machine-dependent Makefiles in each directory, so
  256. the operation is not idempotent.
  257.  
  258. It is also possible to install (or clean) only some of the directories:
  259.      make all MACHINE=SUN DIRS=messages
  260.      make clean DIRS='monitors messages'
  261.  
  262. To install only the Makefiles in all subdirectories, use:
  263.      make makefiles MACHINE=<machine>
  264.  
  265. directory everything that is needed to compile and link p4 programs, 
  266. do:
  267.  
  268.      make install INSTALLDIR=<dir>
  269.  
  270. minimal set of directories, copy the relevant `.a' and `.h' files
  271. into it, and test the installation by mking a small set of examples.
  272.  
  273. *Note Getting Started:: for instructions on how to run some example
  274. programs after you have installed p4.
  275.  
  276.  
  277. Installing the Documentation
  278. ----------------------------
  279.  
  280.  
  281.  
  282. The directory `p4/doc' contains this manual as well as files that
  283. require installation.  This manual was prepared with the
  284. `latexinfo' package from GNU emacs; thus it can be made available online
  285. through `info'.  The files in `p4/doc' are:
  286.  
  287. p4.tex     
  288.       the latex source for this manual, which uses the latexinfo style
  289.      
  290. latexinfo.sty     
  291.       the sytle file needed to latex this manual
  292.      
  293. p4.info     
  294.       the `info' version of this manual, ready to be put
  295.      into the directory where `info' files are kept at your site.  Check
  296.      the value of your `emacs' variable INFO-DIRECTORY.
  297.      
  298. p4.txt     
  299.       plain ascii text of the manual, in case nothing else works.
  300.      
  301. p4.1     
  302.       unix man page for the p4 library
  303.      
  304. p4f.1     
  305.       unix man page for the Fortran interface to p4
  306.      
  307.  
  308.  
  309. The Postscript version of this manual is available by anonymous `ftp'
  310. from `info.mcs.anl.gov', in the directory `pub/p4'.  The file to
  311. get (in binary mode) is `p4man.ps.Z'.
  312.  
  313.  
  314.  
  315. Examples included with the Distribution
  316. ---------------------------------------
  317.  
  318.  
  319.  
  320. A good way to see how various p4 functions are used is to look at the example
  321. programs included in the distribution.  The `p4/monitors' directory
  322. contains shared-memory examples written in C that use monitors, including one
  323. instrumented with ALOG.  The `p4/messages' subdirectory contains
  324. message-passing examples written in C.  The programs in `p4/messages_f'
  325. are Fortran message-passing examples, and the `p4/contrib' and
  326. `p4/contrib_f' directories contain a number of miscellaneous examples
  327. contributed by users.  In each directory there is a `README' that
  328. describes the individual examples.
  329.  
  330.  
  331.  
  332. Getting Started
  333. ===============
  334.  
  335.  
  336.  
  337. The easiest way to get started with p4 is to play with some of the
  338. sample programs provided with the system.
  339.  
  340.  
  341.  
  342. A Message-Passing Example
  343. -------------------------
  344.  
  345.  
  346. We will begin with a message-passing example in the sub-directory named
  347. `p4/messages'.  The code for the program is in the files `sr_test.c'
  348. and `sr_user.h'.
  349.  
  350.  
  351.  
  352. Program Description
  353. -------------------
  354.  
  355.  
  356. As the name implies, this program is an example of p4's send/receive
  357. functionality.  Briefly, it is a simple program that runs a master
  358. process and some slave processes.  The master and the set of slaves
  359. form a ring of processes in which the master reads a message from stdin
  360. and sends a copy of the message to the first slave, which passes it on;
  361. the last slave passes the message back to the master.  If the master
  362. receives an undamaged copy of the message, it assumes that all went
  363. well, and reads another message.  Note that the ring of processes is a
  364. logical structure in which each process assumes that its
  365. predecessor in the ring is the process with the next lower id, and
  366. its successor is the process with the next higher id.  The master
  367. has id 0 (zero) and has the process with the largest id as its
  368. predecessor.
  369.  
  370.  
  371.  
  372.  
  373. Analysis of the Program
  374. -----------------------
  375.  
  376.  
  377. The first executable p4 statement in a program should be:
  378.      p4_initenv(&argc,argv); 
  379.  
  380. This initializes the p4 system and allows p4 to extract any command
  381. line arguments passed to it, e.g. debugging parameters.  
  382.  
  383. Similarly, the last executable p4 statement in a program should be:
  384.      p4_wait_for_end(); 
  385.  
  386. This waits for termination of p4 processes and performs some cleanup
  387. operations.
  388.  
  389. The procedure `p4_get_my_id' returns the unique integer id assigned
  390. to the calling process by p4.
  391.  
  392. The statement:
  393.      p4_create_procgroup();
  394.  
  395. reads a procgroup file that the user builds and creates the set of
  396. slaves described in that file.  Obviously this statement must be
  397. executed before any slaves can be assumed to exist.  This procedure
  398. is the method you must use to create processes that do message-passing.
  399.  
  400. The procedure `p4_clock' returns an integer that represents
  401. wall-clock time in milliseconds.  It is typically used to retrieve the
  402. time before and after some work, the difference representing the time to
  403. do that work.  Note that there is also a `p4_ustimer' that is useful on
  404. those machines that support a microsecond timer.
  405.  
  406. The procedures `p4_send' and `p4_sendr' are two of several 
  407. p4 procedures that are available for sending messages to other processes.
  408. They take as arguments the message type, the id of the "to" process,
  409. the address of the message, and the message length.
  410.  
  411. The procedure `p4_recv' receives a message from another process and
  412. sets the values of all four parameters.  `P4_recv' will automatically
  413. retrieve a buffer in which to place a received message, thus
  414. `p4_msg_free' may be called to free that buffer when it is no longer
  415. needed.
  416.  
  417. The procedure `p4_num_total_slaves' is one of several procedures that
  418. the user can invoke to determine information about the current execution.
  419.  
  420. To run this program, you need to create a procgroup file that describes
  421. where all slave processes are to be executed 
  422. (*Note Specifying Processes in the Procgroup File::).  We will assume that
  423. you have an example procgroup file (named `procgroup') in the 
  424. `p4/messages' directory, and can run `sr_test' by merely typing:
  425.      sr_test
  426.  
  427. If the procgroup file is elsewhere, then you must type:
  428.      sr_test -pg  {pathname_of_procgroup_file}
  429.  
  430.  
  431. Another example that is made by default is the program `systest'.  It
  432. tests a number of the message-passing features of p4.
  433.  
  434.  
  435.  
  436. Specifying Processes in the Procgroup File
  437. ==========================================
  438.  
  439.  
  440.  
  441. The procgroup file is the only portion of the interface that is very
  442. likely to change through multiple versions of p4.  As new architectures
  443. are supported, it is hoped that we can merely alter the procgroup file
  444. format to reflect any new features.  (Of course new procedure calls may 
  445. also be required, but existing procedure calls will remain unchanged 
  446. when possible).
  447.  
  448. The current format of a procgroup file is as follows:
  449.      local n [full_path_name] [loginname]
  450.      remote_machine n full_path_name [loginname]
  451.      .
  452.      .
  453.      .
  454.  
  455.  
  456. On cube and mesh architectures, the program is started via some
  457. special command executed from the host machine.  In such cases, the
  458. procgroup file name can be specified to the special command line along
  459. with the program name (see for example the `runcube' and `rundelta'
  460. shell scripts in the `p4/messages' subdirectory).  In those cases 
  461. where no special command is required, no special handling is required 
  462. for the procgroup filename.
  463.  
  464. The first line of a procgroup file must be "local n" where n is the
  465. number of slave processes that are in the same cluster as the master.
  466. The full path name on the "local" line is ignored on machines other
  467. than cube and mesh machines.  The subsequent lines contain either
  468. three or four fields:
  469.   1. the name of a remote machine on which slave processes are to be created.
  470.   2. the number of slaves that are to be created on that machine, 
  471.      i.e. be in the same cluster (note that on machines that support it, 
  472.      the processes in a cluster will share memory)
  473.   3. the full path name of the executable slave program
  474.   4. optionally, the user login name on the remote machine, if different from 
  475.      that on the host machine.
  476.  
  477.  
  478. As an example, let's assume that you have a network of three Sun 
  479. workstations named sun1, sun2, and sun3.  We will also assume that you 
  480. are working on sun1 and plan to run a master process there.  
  481. If you would like to run one process on each of the other Suns, then you 
  482. might code a procgroup file that looks like:
  483.  
  484.          # start one slave on each of sun2 and sun3
  485.          local 0 
  486.          sun2  1  /home/mylogin/p4pgms/sr_test
  487.          sun3  1  /home/mylogin/p4pgms/sr_test
  488.  
  489.  
  490. Lines beginning with `#' are comments.
  491.  
  492. Next, let's assume that you have a Sequent Symmetry (named symm) and an
  493. Encore Multimax (named mmax).  We will also assume that you are working
  494. on symm, and plan to run the master there.  If you would like to run
  495. two processes on symm (in addition to the master) and two on mmax, then 
  496. you might code a procgroup file that looks like:
  497.  
  498.          local 2 
  499.          mmax  2  /mmaxfs/mylogin/p4pgms/sr_test
  500.  
  501.  
  502. P4 also permits you to treat the symmetry as a remote machine even when 
  503. you are running the master there.  Thus, you might code a procgroup file 
  504. as follows:
  505.  
  506.          local 2 
  507.          symm  2  /symmfs/mylogin/p4pgms/sr_test
  508.          mmax  2  /mmaxfs/mylogin/p4pgms/sr_test
  509.  
  510.  
  511. In this example, there are seven processes running.  Five of the
  512. processes are on symm, including the master.  Two of the processes on
  513. symm are in the master's procgroup and two are running in a separate
  514. procgroup as if they were on a separate machine.  Of course, the last
  515. two are running on mmax.
  516.  
  517. Some notes about the contents of the procgroup file should be made at
  518. this point.  First, the value of `n' on the local line can be zero,
  519. i.e. the master may have no local slaves.  Second, the local machine
  520. may be treated as if it is a remote machine by merely entering it in
  521. some line as a remote machine.  Third, a single machine may be treated
  522. as multiple remote machines by having the same remote machine name
  523. entered on multiple lines in the procgroup file.  Fourth, if a single
  524. machine is listed multiple times, those processes specified on each
  525. line form a single cluster (share memory).  Fifth, the cluster size
  526. specified for a uniprocessor should be 1, because all slaves in a
  527. cluster are assumed to run in parallel and to share memory.
  528.  
  529. We refer to the original (master) process as the "big master".  The
  530. first process created in each cluster is the "remote master" or the
  531. "cluster master" for that cluster.  
  532. All p4-managed processes (see the procedure `p4_create_procgroup') 
  533. have unique integer id's beginning with 0.
  534. The processes within a cluster are numbered consecutively.
  535.  
  536.  
  537.  
  538. Developing a Simple p4 Program
  539. ==============================
  540.  
  541.  
  542. The real fun associated with any computing environment arrives when you
  543. actually type in a program and run it yourself.  We will assume that
  544. you have successfully installed p4 on your own system and are ready to
  545. write a small program, compile it, and run it.
  546.  
  547.  
  548.  
  549. A Minimal Example
  550. -----------------
  551.  
  552.  
  553. We will start with a tiny program in which the slave processes do no work, and
  554. then expand its capabilities.  Edit a file called `p4simple.c' and type:
  555.  
  556.      
  557.          #include "p4.h"
  558.      
  559.          main(argc,argv)
  560.          int argc;
  561.          char **argv;
  562.          {
  563.              p4_initenv(&argc,argv);
  564.              if (p4_get_my_id() == 0)
  565.                  p4_create_procgroup();
  566.              slave();
  567.              p4_wait_for_end();
  568.          }
  569.      
  570.          slave()
  571.          {
  572.              printf("Hello from %d++",p4_get_my_id());
  573.          }
  574.      
  575.  
  576.  
  577. This is one of the simplest p4 programs that you can write.  Let's
  578. examine it.  The `#include "p4.h"' statement must appear in all
  579. programs that use any p4 features.  The procedure `p4_initenv'
  580. must be invoked before any other p4 procedures, and
  581. `p4_wait_for_end' must be invoked after all p4 processing is
  582. completed.  The `p4_get_my_id' returns a unique integer id for
  583. each process, beginning with 0.  The procedure
  584. `p4_create_procgroup' should only be invoked once (by process 0),
  585. and is responsible for creating all other processes.  The way in which
  586. `p4_create_procgroup' determines how many other processes there
  587. should be, and where they should run, will be discussed shortly.
  588.  
  589. All processes that this program executes invoke the slave procedure,
  590. including process 0.  Thus, in this program, the master process acts
  591. just like all other processes once it gets the environment
  592. established.
  593.  
  594. To understand how things get started, let's consider two separate
  595. situations.  In the first situation, all processes are running on a
  596. single machine.  Then, when process 0 starts, it executes the
  597. `p4_create_procgroup' procedure to start all other slaves.  The other
  598. slaves are started on the same machine by means of a UNIX {fork},
  599. and they immediately invoke a procedure named slave.  Thus, these local
  600. slaves do not ever execute the main procdure.
  601.  
  602. In the second situation, there may be slaves running both on the same
  603. machine as process 0, and slaves running on other machines as well.
  604. In this situation, the first slave running on a remote machine will
  605. need to execute the main procedure.  It will discover that it is not
  606. process 0.  However, as part of initialization, process 0 will
  607. direct it to fork any additional slaves required on the same machine.
  608.  
  609.  
  610. In some ways, the above example can be used a a prototype for all p4 programs,
  611. just by varying the content of the `slave' routine.  The routine name
  612. `slave' is built into p4 in order to enable the same code to be run on
  613. shared-memory machines via `fork' or on remote machines via `rsh'.
  614. Different wrappers are automatically put around the `slave' code.  These
  615. wrappers depend on the user code being called `slave'.  Thus your p4
  616. program must contain a subroutine called `slave' in order to link
  617. properly. 
  618.  
  619.  
  620.  
  621. A More Complicated Example
  622. --------------------------
  623.  
  624.  
  625. Now, let's make the slave process a little bit more interesting.  Let's
  626. assume that we have `nprocs' slaves with ids 
  627. 0, 1, 2, ... `nprocs' -1.  And, we want to write a program in which
  628. every process sends a single message to every other slave, and then
  629. receives a message from every other slave.  We might alter the code for
  630. the slave procedure to be the following:
  631.  
  632.          slave()
  633.          {
  634.              char *incoming, *msg = "hello";
  635.              int myid, size, nprocs, from, i, type;
  636.      
  637.              myid = p4_get_my_id();
  638.              nprocs = p4_num_total_ids();
  639.              for (i=0; i < nprocs; i++)
  640.              {
  641.                  if (i != myid)
  642.                      p4_send(100, i, msg, strlen(msg)+1);
  643.              }
  644.              for (i=0; i < nprocs - 1; i++)
  645.              {
  646.                  type = -1;
  647.                  from = -1;
  648.                  incoming = NULL;
  649.                  p4_recv(&type,&from,&incoming,&size);
  650.                  printf("%d received msg=:%s: from %d++",myid,incoming,from);
  651.                  p4_msg_free(incoming);
  652.              }
  653.          }
  654.  
  655.  
  656. This program demonstrates several features of p4's support for
  657. message-passing.  Before we get into the specifics however, let's
  658. examine the overall logic of the program.  Each process determines its
  659. own id and the total number of processes executing in this run
  660. (including process 0).  Then, in the first for-loop, each process sends
  661. a single message to each of the other processes.  Finally, in the
  662. second for-loop, each process receives a message from each of the other
  663. processes.
  664.  
  665. The `p4_send' call requires 4 arguments:
  666.    * a message type (arbitrarily chosen to be 100 here)
  667.    * the id of the process to receive the message
  668.    * the message itself
  669.    * the size of the message
  670.  
  671.  
  672. The use of `p4_recv' is slightly more complicated.  First, we
  673. assign -1 to each of the parameters type and from.  This is done
  674. because -1 represents a wildcard value indicating we are willing to
  675. receive a message of any type from any process.  Here, we could have
  676. coded type to be 100, and specified from equal to the value of i each
  677. time through the loop (skipping our own id).  By setting incoming to
  678. NULL, we have also indicated to `p4_recv' that we do not have a
  679. buffer in which to place the received message, so `p4_recv' should
  680. obtain a buffer for us and place the message in that buffer.
  681. `p4_recv' treats these three parameters as both input and output
  682. values.  Thus, it alters the value of each such that type and from
  683. indicate the type of message received and the id of the process that
  684. sent it.  The value of `incoming' is altered to point to the
  685. buffer where the message was placed.  The `size parameter' is
  686. strictly an output parameter and iindicates the size of the received
  687. message.  It is possible for the user to provide his own buffer; this
  688. will be demonstrated later.
  689.  
  690.  
  691. Finally, note that `p4_msg_free' frees the message buffer obtained by
  692. `p4_recv.' The procedure `p4_msg_free' should be called only after
  693. the contents of the message are no longer needed.  `P4_msg_free' should
  694. be used to free these buffers because, although a user only sees the data
  695. portion of a message, p4 internally represents a message as a structured data
  696. item.
  697.  
  698. To compile and link this program for execution, you need to create a
  699. makefile.  We will assume that you have installed p4 in
  700. `/usr/local/p4' and that you have typed the program above into a
  701. file name `p4simple.c' in the directory
  702. `/home/mylogin/p4pgms'.
  703.  
  704. To build your makefile, copy the file
  705.          /usr/local/p4/messages/makefile.proto
  706.  
  707. into your working directory.  This is a prototype makefile that
  708. contains machine-independent information, and which p4 can use to build a
  709. machine-specific makefile for your program.  This prototype makefile contains
  710. information about several sample programs that demonstrate
  711. message-passing in p4.  If you edit this file, you will see information
  712. for making a program named `sr_test'.  Do a global change of
  713. `sr_test' to `p4simple'.  You should also change the value of
  714. `P4_HOME_DIR'.  It should contain the full
  715. pathname of the p4 system, e.g. `/usr/local/p4'.  Now change
  716. directories to `/usr/local/p4' and type:
  717.  
  718.      make makefiles MACHINE=<machine_type> DIRS=/home/mylogin/p4pgms
  719.  
  720. where `<your_machine_type>' is the machine type that you specified when
  721. you installed p4 on your machine.  Now, you should be able to change
  722. back to your directory and see a file named Makefile there.  
  723. You should then be able to type:
  724.  
  725.          make p4simple
  726.  
  727.  
  728. There is one last piece missing before you can execute your program.
  729. Recall that `p4_create_procgroup' needs to know how many processes
  730. to start and where to start them; it reads a file (called a
  731. "procgroup file") to gather this information.  p4 always assumes
  732. that you have a master process, and that you describe the slave
  733. processes (process groups) in the procgroup file.  You can name a
  734. procgroup file any name you choose, but `procgroup' is the default
  735. name.  The information contained in procgroup files can get fairly
  736. involved, but if you have a computer that supports shared memory among
  737. processes, then you can code a very simple example at first.
  738.  
  739. Let us suppose first that you want to run your program on a network of
  740. workstations.  Then your procgroup should look something like:
  741.  
  742.          local O
  743.          some.network.machine 1 /home/me/p4progs/p4simple
  744.  
  745.  
  746. This file indicates that you wish to run only the master on the local machine
  747. (the one you are logged into when you execute the program) and one slave on
  748. the machine `some.network.machine'.
  749.  
  750. Now, all you have to do to run your program is type:
  751.  
  752.          p4simple
  753.  
  754.  
  755. You should see a line printed each time a process receives a message
  756. from another process (on some machines, there may be a restriction that
  757. only one process can do I/O, however such restrictions are not
  758. common).  Experiment by changing the number of slaves indicated in the
  759. procgroup file.
  760.  
  761. You may notice that even a small p4 program becomes large when linked
  762. with the p4 library.  You might consider using `strip' to reduce
  763. the size or removing `-g' from the CFLAGS in the makefile.
  764.  
  765.  
  766. Command-Line Arguments
  767. ======================
  768.  
  769.  
  770.  
  771. The command-line arguments to a p4 program are all optional.
  772.      -help           get this information and the version number, then exit
  773.      -pg             procgroup_file
  774.      -dbg            set debug level 
  775.      -rdbg           set remote debug level
  776.      -gm             set globmemsize
  777.      -dmn            provide local domainname
  778.      -outfile        output file for master
  779.      -routfile       output file prefix for remote masters
  780.      -ssport         port# private port number for secure server
  781.      -p4log          enable internal p4 logging by alog
  782.      -p4version      print the current p4 version number
  783.  
  784.  
  785.  
  786.  
  787. The p4 Function Library
  788. =======================
  789.  
  790.  
  791. Overview of the Library
  792. -----------------------
  793.  
  794.  
  795. In the following sections, we provide details for each p4 function in the
  796. library.  The procedures are gathered into the following groups:
  797.  
  798.    * Functions for managing processes and clusters
  799.    * Functions for message passing
  800.    * Functions for shared memory
  801.    * Functions for timing p4 programs
  802.    * Functions for debugging p4 programs
  803.    * Miscellaneous functions
  804.    * Fortran interface functions
  805.  
  806.  
  807.  
  808. Return Codes from p4 Functions
  809. ------------------------------
  810.  
  811.  
  812.  
  813. Most p4 functions return -1 if an error occurs.  Some, however, call the
  814. function `p4_error' when severe errors occur.  This function prints a
  815. message and then attempts to terminate all of the user's processes
  816. *Note Functions for Debugging p4 Programs::.
  817.  
  818.  
  819. p4 Functions for Managing Processes and Clusters
  820. ================================================
  821.  
  822.  
  823. In some situations a p4 procedure will give an error message and then
  824. exit.  This is typically done as a result of a failed system call and
  825. handled by calling the p4 procedure named `p4_error' that examines the
  826. return values from socket procedures, etc.  Most of the time however,
  827. the procedures simply return a value.  Some of the procedures return no
  828. value and thus are declared to return `VOID'.  Some of the
  829. procedures return either a pointer to a character string or `NULL';
  830. `NULL' indicates an error.  The remaining procedures return an
  831. integer value; (-1) indicates an error.
  832.  
  833.  
  834.  
  835. Functions for Process Management
  836. --------------------------------
  837.  
  838.  
  839.  
  840. In this section we describe the p4 functions needed for basic creation and
  841. termination of processes.
  842.  
  843.  
  844.      int p4_initenv(argc,argv)
  845.      int *argc;
  846.      char **argv;
  847.  
  848. should be called by your program before an attempt is made to use
  849. any p4 procedures or data areas.  We suggest making it the first executable
  850. statement in your program.  `p4_initenv' parses the command line
  851. arguments and extracts the ones intended for p4 ignoring all others (see the
  852. discussion of command line arguments).  Note that you pass the address of
  853. `argc' to `p4_initenv' so that it can actually remove its own
  854. arguments before your program looks at them.
  855.  
  856.  
  857.      int p4_create(fxn)
  858.      int (*fxn)();
  859.      
  860.      
  861.      int p4_create_procgroup()
  862.  
  863. There are two procedures that you can use to create processes in p4,
  864. `p4_create_procgroup' and `p4_create'.  Processes created via
  865. `p4_create' are said to be "user-managed" whereas those created
  866. by `p4_create_procgroup' are "p4-managed".  The p4-managed
  867. processes are automatically assigned unique id's (beginning with 0 for
  868. the big master), they have message queues allocated for them so that
  869. they can do message-passing, and they are able to run either on a
  870. shared-memory multiprocessor with the creating process or they can run
  871. on a separate machine.  Processes created via `p4_create' do not
  872. have any of these advantages.  They must develop their own id's, they
  873. cannot do message-passing, and they can only run on a shared-memory
  874. multiprocessor with the creating process.  The only disadvantage of
  875. `p4_create_procgroup' is that you must build a `procgroup'
  876. file describing the set of required slave processes before the master
  877. program begins execution.  This eliminates the possibility of
  878. determining late in the execution exactly how many processes you want
  879. to use to solve a problem.  Generally, this is not a problem,
  880. especially since we can combine `p4_create_procgroup' and
  881. `p4_create' in the following way: You can use
  882. `p4_create_procgroup' to develop a network of processes that talk
  883. to each other via messages.  Each of those processes can create further
  884. processes to help it out as necessary.  The original set of processes
  885. communicate with their local slaves through shared data areas and with
  886. each other via message-passing.
  887.  
  888. `p4_create' receives one argument that is a pointer to a function.  It
  889. creates a single new process that executes the indicated function.  The
  890. new process may share data areas (in shared memory) with the parent
  891. process.  However, the new process is not managed by the p4 system in
  892. the sense that it is not assigned an id, it cannot pass messages, etc.
  893. The only p4 procedure that deals with user-managed slaves is `p4_create'.
  894. No other procedures are even aware of their existence.
  895.  
  896. `p4_create_procgroup' reads your `procgroup' file to determine the 
  897. number of slave processes to create and where they are to be placed.  It
  898. builds a procgroup table that describes all created processes and gives
  899. a copy of the table to each process.  The processes then use the table
  900. to discover how to communicate with each other (processes in a cluster
  901. can send messages directly through shared memory or some other
  902. vendor-specific mechanism), others communicate via sockets). 
  903. An alternative method is to build the table in memory yourself and use
  904. `p4_startup'.
  905.  
  906. The effect of `p4_create_procgroup' can be obtained in another way if a
  907. system would prefer to use its own way of specifying the locations of
  908. processes.  A user may allocate the procgroup data structure and then fill it
  909. in "by hand" rather than by reading a file in p4 procgroup format.  The
  910. following procedures support this method of starting processes.
  911.  
  912.  
  913.      struct p4_procgroup *p4_alloc_procgroup()
  914.  
  915. allocates a procgroup data structure of the form described in `p4.h'.
  916. The formats of individual entries (`p4_procgroup_entry') are given there
  917. as well. 
  918.  
  919.  
  920.      int 4_startup(pg)
  921.      struct p4_procgroup *pg;
  922.  
  923. starts processes as specified by an an already-created procgroup data
  924. structure allocated by `p4_alloc_procgroup' and filled in by the user
  925. using the structures `p4_procgroup_entry' and `p4_procgroup'.
  926.  
  927.  
  928.  
  929.      VOID p4_wait_for_end()
  930.  
  931. is the p4 termination/cleanup procedure that you should invoke at the
  932. end of every execution of a program that uses p4.  
  933. It does some termination processing and then waits for slave processes 
  934. to end.
  935.  
  936.  
  937.      int p4_get_my_id()
  938.  
  939. returns an integer value representing the id of the process assigned by
  940. the p4 system.  If the process is not a p4-managed process, the value
  941. (-1) is returned.
  942.  
  943.  
  944.      int p4_num_total_ids()
  945.  
  946. returns an integer value indicating the total number of ids started
  947. by p4 in all clusters, including the big master and all remote masters.
  948.  
  949.  
  950.      int p4_num_total_slaves()
  951.  
  952. returns an integer value indicating the total number of processes started
  953. by p4 in all clusters, including all remote masters but not the big master.
  954.  
  955.  
  956. Functions for Cluster Management
  957. --------------------------------
  958.  
  959.  
  960.  
  961. The p4 system supports the "cluster" model of parallel computation, in
  962. which subsets of processes share memory with one another, with the clusters
  963. communicating via messages.  A procgroup file for a program written for the
  964. cluster model might look like this:
  965.  
  966.          local 4
  967.          alliant1.abc.edu     5 /home/me/myprog
  968.          alliant2.abc.edu     5 /home/me/myprog
  969.          encore.somewhere.edu 5 /usrs/me/myprog
  970.  
  971.  
  972. This would specify a total of 20 processes, 5 (including the master) running
  973. on the local machine (here assumed to be capable of supporting five processes
  974. that share memory) together with 5 slaves each on three other shared-memory
  975. machines.
  976.  
  977.  
  978.      VOID p4_get_cluster_ids(start,end)     
  979.      int *start;
  980.      int *end;
  981.  
  982. receives pointers to two integers.  It places the p4-assigned id's of
  983. the first and last ids within the current cluster into the two
  984. arguments (including the remote master).
  985.  
  986.  
  987.      int p4_get_my_cluster_id()
  988.  
  989. returns a unique id (relative to 0) within a cluster of p4-managed
  990. processes.  Thus, a cluster master will always have a cluster id of 0.
  991. It is not clear that a separate cluster id is really useful, but the
  992. functionality is provided just in case.
  993.  
  994.  
  995.      BOOL p4_am_i_cluster_master()
  996.  
  997. returns a BOOL value indicating whether the invoking process is the
  998. "cluster master" process within its cluster.
  999.  
  1000.  
  1001.      int p4_num_cluster_ids()
  1002.  
  1003. returns an integer value indicating the number of ids in the current
  1004. cluster as started by `p4_create_procgroup'.  
  1005.  
  1006.  
  1007.  
  1008. Functions for Message Passing
  1009. =============================
  1010.  
  1011.  
  1012.  
  1013. P4 supports a set of send/receive procedures.  These procedures are
  1014. "generic" in the sense that they do not know whether a message must
  1015. travel across a network or through shared memory, or via some other
  1016. mechanism.  They depend on a lower-level set of procedures that handle
  1017. local or network (remote) communications.  By default, the messages
  1018. are assumed to be typed.  If the user wishes to use untyped messages,
  1019. he can hide the typing by coding some very simple C macros that always
  1020. use a single message type.
  1021.  
  1022.  
  1023.  
  1024. Explicit Sending and Receiving of Messages
  1025. ------------------------------------------
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.      p4_send(type,to,msg,len)
  1038.      p4_sendr(type,to,msg,len)
  1039.      p4_sendx(type,to,msg,len,datatype)
  1040.      p4_sendrx(type,to,msg,len,datatype)
  1041.      p4_sendb(type,to,msg,len)
  1042.      p4_sendbr(type,to,msg,len)
  1043.      p4_sendbx(type,to,msg,len,datatype)
  1044.      p4_sendbrx(type,to,msg,len,datatype)
  1045.      
  1046.      int type, to, len, datatype;
  1047.      char *msg;
  1048.  
  1049.  
  1050. Each of these procedures sends a message.  The `type' argument is
  1051. an integer value chosen by the user to represent a message type.  The
  1052. `to' argument is an integer value that specifies the p4-id of the
  1053. process that should receive the message.  The `len' argument
  1054. contains the length of the message to be passed.  Note that some of the
  1055. procedures have a "b" in their name, e.g.  `p4_sendb'.  These
  1056. procedures assume that the msg is in a buffer that the user obtained
  1057. earlier via a `p4_msg_alloc'; otherwise, the buffer is assumed to
  1058. be in the user's local space, and may cause the message to be copied
  1059. internally.  The procedures with an "r" in the name do not return
  1060. until an acknowledgement is received from the `to' process (the
  1061. "r" stands for rendezvous).  Those procedures with an "x" in the
  1062. name take an extra argument (datatype) that specifies the type of data
  1063. in the message; these procedures will use that information to call XDR
  1064. for data conversion if the message is being passed to a machine of a
  1065. different architecture, i.e. where the internal representation may be
  1066. different.
  1067.  
  1068.  
  1069.  
  1070.      BOOL p4_messages_available(req_type,req_from)
  1071.      int *req_type,*req_from;
  1072.  
  1073. returns a BOOL value indicating whether the process has any messages available
  1074. or not.  The parameters `req_type' and `req_from' are both pointers
  1075. to integers; they are used as {both} input and arguments.  On input,
  1076. `req_type' has a value that indicates the type of message that the user
  1077. wishes to check for availability (-1 indicates any type).  The variable
  1078. `req_from' is used similarly to indicate who a message is desired from.
  1079.  
  1080.  
  1081.  
  1082.      int p4_recv(req_type,req_from,msg,len_rcvd)
  1083.      int *req_type,*req_from,*len_rcvd;
  1084.      char **msg;
  1085.  
  1086. pointer to a `char'.  If this value is NULL, then p4 will allocate the
  1087. buffer for the message according to its length.  That is, one need not know
  1088. ahead of time the length of a message being received.  If this value is not
  1089. NULL, then it points to a p4 message buffer that the user has obtained via
  1090. `p4_msg_alloc'.  The `len_rcvd' argument is a pointer to an integer
  1091. that is assigned the length of the received message.  `Req_type' and
  1092. `req_from' are both pointers to integers; they are used as both input and
  1093. arguments.  On input, `req_type' has a value that indicates the type of
  1094. message that the user wishes to receive (-1 indicates any type).  It will
  1095. block until a message of that type is available.  `Req_from' is used
  1096. similarly to indicate who a message is desired from.  One important note about
  1097. this procedure is that it obtains the area in which to place a message, and
  1098. the user must explicitly free that area when finished with it (see
  1099. `p4_msg_free').  There is an option available with `p4_recv' in
  1100. which the user can provide his own buffer rather than having p4 allocate it.
  1101. To do this, the user points `msg' to a buffer that he must obtain via a
  1102. call to `p4_msg_alloc' (see below).  Then he assigns `len_rcvd' a
  1103. value which is the length of that buffer.  In this case, `len_rcvd' is
  1104. both an input and output variable.  In addition, no `p4_msg_free' need be
  1105. performed if the same buffer is going to be re-used multiple times.
  1106.  
  1107.  
  1108.  
  1109.      char *p4_msg_alloc(len)
  1110.      int len;
  1111.  
  1112. obtains a pointer to a buffer area that can be used to receive a 
  1113. message.  This procedure should be used for this task because a 
  1114. message has hidden information which the user is unaware of and 
  1115. therefore should not use malloc to obatin the area.
  1116.  
  1117.  
  1118.  
  1119.      VOID p4_msg_free(m)
  1120.      char *m;
  1121.  
  1122. frees the message pointed to by `m.'  This procedure should be used
  1123. for this task because a message has hidden information which the
  1124. user is unaware of and therefore cannot be freed by the user.
  1125.  
  1126.  
  1127.  
  1128. Global Operations
  1129. -----------------
  1130.  
  1131.  
  1132.  
  1133. P4 supports a number of operations for dealing with all processes at once.
  1134.  
  1135.  
  1136.      p4_broadcastx(type, data, data_len, data_type)
  1137.      int type;
  1138.      char *data;
  1139.      int data_len, data_type;
  1140.  
  1141.  
  1142.  
  1143.      p4_broadcast(type, data, data_len)
  1144.      int type;
  1145.      char *data;
  1146.      int data_len;
  1147.  
  1148. provide the ability to broadcast messages like `p4_send' and
  1149. `p4_sendx'.
  1150.  
  1151.  
  1152.      p4_global_op(type,x,nelem,size,op,data_type) 
  1153.      int type;
  1154.      char *x;
  1155.      int size, nelem;
  1156.      int (*op)();
  1157.      int data_type;
  1158.  
  1159. where `op' is one of:
  1160.      p4_int_absmax_op()
  1161.      p4_int_absmin_op()
  1162.      p4_int_max_op()
  1163.      p4_int_min_op()
  1164.      p4_int_mult_op()
  1165.      p4_int_sum_op()
  1166.      p4_dbl_absmax_op()
  1167.      p4_dbl_absmin_op()
  1168.      p4_dbl_max_op()
  1169.      p4_dbl_min_op()
  1170.      p4_dbl_mult_op()
  1171.      p4_dbl_sum_op()
  1172.      p4_flt_absmax_op()
  1173.      p4_flt_absmin_op()
  1174.      p4_flt_max_op()
  1175.      p4_flt_min_op()
  1176.      p4_flt_mult_op()
  1177.      p4_flt_sum_op()
  1178.  
  1179.  
  1180. and `data_type' is one of `P4INT', `P4LNG', `P4FLT', or
  1181. `P4DBL'.
  1182.  
  1183. This collection of routines provide the ability to do a variety of
  1184. global operations.  See the example programs in subdirectory
  1185. `p4/contrib'.  They apply the commutative operation `op' globally 
  1186. to `x' on an element-by-element basis and broadcast the result to 
  1187. all nodes.  That is each process ends up with
  1188.  
  1189.         for (i=0; i<n; i++)
  1190.               x[i] = x[node 0][i] op x[node 1][i] op x[node 2][i] op ...
  1191.  
  1192. `op' should be of the form
  1193.  
  1194.           VOID op(char *x, char *y, int nelem)
  1195.           {
  1196.               data_type *a = (data_type *) x;
  1197.               data_type *b = (data_type *) y;
  1198.      
  1199.               while (nelem--)
  1200.                   *a++ operation= *b++;
  1201.           }
  1202.  
  1203. where `data_type' and `operation' are chosen appropriately.
  1204.  
  1205. The order in which nodes apply the operation is undefined (hence
  1206. `op' must be commutative). The communication may be internally
  1207. sub-blocked so the function `op' should not be hardwired to specific
  1208. vector lengths.
  1209.  
  1210. This is still a relatively primitive version, which gathers the necessary data
  1211. up a balanced binary tree and then uses `p4_broadcast' to send the
  1212. results back. 
  1213.  
  1214.  
  1215.  
  1216.      VOID p4_global_barrier(type)
  1217.      int type;
  1218.  
  1219. This procedure takes one argument which is the message type to be 
  1220. used for internal message-passing.  It causes the invoking process to
  1221. hang until all processes specified in the procgroup file have invoked 
  1222. the procedure.
  1223.  
  1224.  
  1225.  
  1226. Functions for Shared Memory
  1227. ===========================
  1228.  
  1229.  
  1230.  
  1231. Managing Shared and Local Memory
  1232. --------------------------------
  1233.  
  1234.  
  1235.  
  1236.      char *p4_malloc(n)
  1237.      int n;
  1238.  
  1239. typically acts like the standard `malloc', but may be rewritten for user 
  1240. systems that require different operation.
  1241.  
  1242.  
  1243.      VOID p4_free(p)
  1244.      char *p;
  1245.  
  1246. typically acts like the standard `free', but may be rewritten for
  1247. user systems that require different operation.
  1248.  
  1249.  
  1250.      char *p4_shmalloc()
  1251.  
  1252. acts like the standard `malloc' except will obtain shared memory on
  1253. machines that support sharing memory among processes.  Compare with
  1254. `p4_malloc'.
  1255.  
  1256.  
  1257.      VOID p4_shfree()
  1258.  
  1259. frees memory obtained with `p4_shmalloc'.  Compare with `p4_free'.
  1260.  
  1261.  
  1262.  
  1263. Shared Memory Data Types
  1264. ------------------------
  1265.  
  1266.  
  1267.  
  1268. The abstraction provided by p4 for managing data in shared memory is
  1269. "monitors".  Good places to learn about the monitor concept in general are
  1270. [pbh:architecture] and [hoare:monitors].  The specific approach
  1271. taken by p4 is described in [lusk-overbeek:p4-book].  P4 provides several
  1272. useful monitors (`p4_barrier_t', `p4_getsub_monitor_t',
  1273. `p4_askfor_monitor_t') as well as a general monitor type to help the user
  1274. in constructing his own monitors (`p4_monitor_t').
  1275.  
  1276.  
  1277. Monitor-Building Primitives
  1278. ---------------------------
  1279.  
  1280.  
  1281.  
  1282. The following functions can be used to construct monitors.  A monitor so
  1283. constructed has the type `p4_monitor_t'.
  1284.  
  1285.  
  1286.      int p4_moninit(m,i)
  1287.      p4_monitor_t *m;
  1288.      int i;
  1289.  
  1290. initializes the monitor pointed to by `m' and gives it `i' queues for
  1291. processes to wait on while they are blocked (see `delay').  One queue is
  1292. sufficient for most purposes.  The queues are numbered beginning with 0.
  1293.  
  1294.  
  1295.      VOID p4_menter(m)
  1296.      p4_monitor_t *m;
  1297.  
  1298. enter the monitor pointed to by m.  By the definition of a monitor,
  1299. access is restricted to a single process in the monitor at a time (if
  1300. everybody plays by the rules).
  1301.  
  1302.  
  1303.      VOID p4_mexit(m)
  1304.      p4_monitor_t *m;
  1305.  
  1306. exits the monitor pointed to by m.  You are of course assumed to have
  1307. previously entered that monitor.
  1308.  
  1309.  
  1310.      VOID p4_mcontinue(m,i)
  1311.      p4_monitor_t *m;
  1312.      int i;
  1313.  
  1314. checks to see if there are any processes blocked on the `i'-th queue of
  1315. the monitor `m' and causes one of them to be released for entry to the
  1316. monitor if so.  If there are no such processes, the invoking process
  1317. simply exits.  Note that a process could have been blocked previously
  1318. by invoking the procedure `p4_mdelay'.  The queues are numbered 
  1319. beginning with 0.
  1320.  
  1321.  
  1322.      VOID p4_mdelay(m,i)
  1323.      p4_monitor_t *m;
  1324.      int i;
  1325.  
  1326. permits a process to delay itself on the `i'-th queue of monitor
  1327. `m' if the process wishes to release the monitor, but wants to be
  1328. waked up by another process later (via the procedure `p4_mcontinue').
  1329. The queues are numbered beginning with 0.
  1330.  
  1331.  
  1332. Some Useful Monitors
  1333. --------------------
  1334.  
  1335.  
  1336.  
  1337. In this section we describe some of the specific monitors that are built into
  1338. the p4 library.  Each of them has its own pre-defined type, which can be
  1339. used to allocate storage for them, which should be in shared memory.
  1340. See the `p4/monitors' directory for examples.  A lock is itself a
  1341. monitor, with no extra delay queues.
  1342.  
  1343.  
  1344.      VOID p4_lock_init(l)
  1345.      p4_lock_t *l;
  1346.  
  1347. initializes the lock `l'.  Must be used prior to any attempts to lock or
  1348. unlock `l'.
  1349.  
  1350.  
  1351.  
  1352.      VOID p4_lock(l)
  1353.      p4_lock_t *l;
  1354.  
  1355. blocks if the lock `l' is already locked, otherwise locks `l'
  1356. and proceeds.
  1357.  
  1358.  
  1359.  
  1360.      VOID p4_unlock(l)
  1361.      p4_lock_t *l;
  1362.  
  1363. unlocks the lock `l'.
  1364.  
  1365.  
  1366.      VOID p4_getsub(gs,s,max,nprocs)
  1367.      p4_getsub_monitor_t *gs;
  1368.      int *s,max,nprocs;
  1369.  
  1370. is a procedure used to obtain the next value of a shared counter
  1371. (subscript).  It takes as its first argument, a pointer to a getsub
  1372. monitor that protects the shared counter.  It assigns the current value
  1373. of the counter to the integer that s points to, and then increments the
  1374. counter by 1.  `p4_getsub_init' initially sets the counter to 0.
  1375. When the counter passes the value `max', all `nprocs'
  1376. processes are returned the value (-1) once, then the counter is reset to
  1377. 0 for further use.
  1378.  
  1379.  
  1380.      VOID p4_getsubs(gs,s,max,nprocs,stride)
  1381.      p4_getsub_monitor_t *gs;
  1382.      int *s,max,nprocs,stride;
  1383.  
  1384. is like `p4_getsub' except that the counter is increased on each call by
  1385. `stride' instead of 1.
  1386.  
  1387.  
  1388.  
  1389.      int p4_getsub_init(gs)
  1390.      p4_getsub_monitor_t *gs;
  1391.  
  1392. initializes the getsub monitor pointed to by `gs'; this initialization
  1393. includes assigning a value of 0 to the counter that the monitor
  1394. protects.
  1395.  
  1396.  
  1397. The standard barrier synchronization pattern is expressed as a monitor.
  1398. There can be multiple barrier monitors, and one can wait for only some
  1399. of the processes at the barrier if this is desired.
  1400.  
  1401.  
  1402.  
  1403.      VOID p4_barrier(b,nprocs)
  1404.      p4_barrier_monitor_t *b;
  1405.      int nprocs;
  1406.  
  1407. causes the executing process to hang until `nprocs' processes execute
  1408. a barrier instruction with a pointer to the same barrier monitor `b'
  1409. as an argument.
  1410.  
  1411.  
  1412.      int p4_barrier_init(b)
  1413.      p4_barrier_monitor_t *b;
  1414.  
  1415. initializes the barrier monitor `b'; this procedure should be invoked
  1416. before you attempt to use the monitor in any operations.
  1417.  
  1418. Finally, the `askfor' monitor functions like a general dispatcher of
  1419. work. 
  1420.  
  1421.  
  1422.  
  1423.      int p4_askfor(af,nprocs,getprob_fxn,problem,reset_fxn)
  1424.      p4_askfor_monitor_t *af;
  1425.      int nprocs;
  1426.      int (*getprob_fxn)();
  1427.      VOID *problem;
  1428.      int (*reset_fxn)();
  1429.  
  1430. requests a new "problem" to work on from the problem pool.  The
  1431. arguments are (1) a pointer to the askfor monitor that protects the
  1432. problem pool, (2) the number of processes that call this procedure
  1433. (with `af') looking for work, (3) a pointer to the user-written procedure
  1434. that obtains a problem from the pool, (4) a pointer that is filled in
  1435. with the address of a user-defined representation of a problem to be
  1436. solved, and (5) a pointer to a user-written procedure to reset when all
  1437. problems in the pool are solved, in case the same monitor is re-used
  1438. for another set of problems later.  `p4_askfor' returns an integer
  1439. indicating whether a problem was successfully obtained or not:
  1440.  
  1441.          -1     : program is terminating (some process called p4_progend)
  1442.           0     : a problem was obtained and "problem" points to it
  1443.           1     : problem solved by exhaustion, i.e. no more problems to get
  1444.           n > 1 : a process found a solution and called p4_probend with code n
  1445.  
  1446. For a detailed discussion of the "askfor" monitor, see
  1447. [lusk-overbeek:p4-book].
  1448.  
  1449.  
  1450.      int p4_update(af,putprob_fxn,problem)
  1451.      p4_askfor_monitor_t *af;
  1452.      int (*putprob_fxn)();
  1453.      VOID *problem;
  1454.  
  1455. updates the problem pool being managed by the askfor monitor.  The
  1456. arguments are (1) a pointer to the askfor monitor that protects the
  1457. problem pool, (2) a pointer to the user-written procedure that puts
  1458. problems into the pool, and (3) a pointer to a user-defined
  1459. representation of a problem to be put in the pool.  `Putprob_fxn'
  1460. should return 1 if it did indeed put a new problem into the pool, so
  1461. that any delayed processes should wake up and re-examine the pool (this
  1462. logic is handled by the `p4_askfor') and 0 if upon entering the
  1463. monitor and examining its potential problem together with the data there
  1464. it decided not to add a new problem to the pool.  It can be assumed that
  1465. the "putprob" logic (defined by `putprob_fxn') is executed inside
  1466. the monitor.
  1467.  
  1468.  
  1469.      int p4_askfor_init(af)
  1470.      p4_askfor_monitor_t *af;
  1471.  
  1472. initializes the askfor monitor `af'; this procedure should be invoked
  1473. before you attempt to use the monitor in any operations.
  1474.  
  1475.  
  1476.      VOID p4_probend(af,code)
  1477.      p4_askfor_monitor_t *af;
  1478.      int code;
  1479.  
  1480. allows the user process to mark a problem as solved early when
  1481. several processes are coordinating their activities via an askfor
  1482. monitor.  The code is an integer value that will be returned to all
  1483. processes when they "askfor" a new sub-problem to work on.
  1484.  
  1485.  
  1486.      VOID p4_progend(af)
  1487.      p4_askfor_monitor_t *af;
  1488.  
  1489. allows a process to cause a return code of (-1) to be returned to all
  1490. processes using an askfor monitor.  This would typically be called by
  1491. a master process to indicate that no more problems are to be solved
  1492. and that all slave processes should terminate.
  1493.  
  1494.  
  1495. Functions for Timing p4 Programs
  1496. ================================
  1497.  
  1498.  
  1499.  
  1500. A small number of simple functions are available for accessing various
  1501. clocks and timers.  
  1502.  
  1503.  
  1504.      int p4_clock()
  1505.  
  1506. returns a value in milliseconds.  This is a wall-clock value, usually obtained
  1507. from the system via `gettimeofday'.  Also see `p4_ustimer' below.
  1508.  
  1509.  
  1510.      p4_usc_time_t p4_ustimer()
  1511.  
  1512. returns a wall-clock time value in microseconds.  The precision of this
  1513. number depends on the timer installed on the individual machine.  In
  1514. some cases the resolution may be no greater than that of `p4_clock()'.
  1515. For arithmetic and printing purposes, the type `p4_usc_time_t' is an
  1516. unsigned long integer.
  1517.  
  1518.  
  1519.      p4_usc_time_t p4_usrollover()
  1520.  
  1521. returns the timer value at which a microsecond timer "rolls over".
  1522. Since `p4_usc_time_t' is a long integer's worth of microseconds, it is
  1523. likely that the timer will roll over (become zero) during even
  1524. medium-length runs.
  1525.  
  1526.  
  1527. Functions for Debugging p4 Programs
  1528. ===================================
  1529.  
  1530.  
  1531.  
  1532. P4 has a set of routines to aid in producing a printed trace of events, both
  1533. user-defined and pre-defined in the p4 system.
  1534.  
  1535.  
  1536.      VOID p4_dprintf(fmt, va_alist)
  1537.      char *fmt;
  1538.      va_dcl
  1539.  
  1540. acts just like the standard `printf' except that the print line is
  1541. preceded by a value that identifies the process.  This value is
  1542. typically the string `pn_u' where `n' represents the
  1543. p4-assigned id and `u' represents the unix-id of the process on its
  1544. host.  However, there are other forms of this value.  For example, the
  1545. big master is represented as `bm_u'.  Also, if a process prints
  1546. before it has a p4-assigned id, then its value will be something like
  1547. `bm_slave_n_u' or `rm_slave_n_u'.  Typically, it is not
  1548. possible for a user program to print anything before being assigned an
  1549. id by p4, but the p4 system itself may use this procedure to print
  1550. messages from a particular process if it encounters problems getting the
  1551. process initialized.
  1552.  
  1553.  
  1554.      VOID p4_dprintfl(level, fmt, va_alist)
  1555.      int level;
  1556.      char *fmt;
  1557.      va_dcl
  1558.  
  1559. is like `p4_dprintf' except that the first argument is an integer
  1560. indicating the debugging level that must be in effect before this
  1561. message will print.  A level of 0 will cause the message to always print.
  1562. If you run a program with the debug level set to 5 (via command-line
  1563. arguments), then all `dprintfl''s with level less than or equal to
  1564. that debug level will print. *Note Command-Line Arguments:: for how to
  1565. set the debug level at run time.
  1566.  
  1567. The debug level can be examined and changed by the user during execution:
  1568.  
  1569.  
  1570.      int p4_get_dbg_level()     
  1571.  
  1572. returns the current debug level for this process and its cluster.
  1573.  
  1574.  
  1575.      VOID p4_set_dbg_level(level)     
  1576.      int level;
  1577.  
  1578. sets the current debug level for this process and its cluster.
  1579. P4 itself is liberally instrumented with `p4_dprintfl''s of level
  1580. 10 and above, leaving levels 0-9 for the user.  The greater the debug
  1581. level of the built-in messages, the greater understanding of p4 needed
  1582. by the user to make sense of them.  However, levels as high as 30 may
  1583. well be useful to the user trying to debug a p4 program.
  1584. Roughly speaking, the following debug levels produce messages about the
  1585. indicated events.
  1586.  
  1587.      level 10:  created process
  1588.                 sent message
  1589.                 received message
  1590.      
  1591.      level 20:  creating process
  1592.                 sending message
  1593.                 receiving message
  1594.                 process starting
  1595.                 process exiting
  1596.      
  1597.      level 30:  waiting for ack
  1598.                 sending ack
  1599.                 sent ack
  1600.                 received ack
  1601.                 queueing message for later receipt
  1602.                 queued message for later receipt
  1603.      
  1604.      level 40:  memory management
  1605.                 buffer management
  1606.      
  1607.      level 50:  reading procgroup
  1608.                 other initialization message exchange
  1609.      
  1610.      level 60:  send-receive details, especially machine-specific traces
  1611.      
  1612.      level 70:  listener interactions:
  1613.                  creating listener
  1614.                  created listener
  1615.                  messages from inside listener
  1616.      
  1617.      level 80:  detailed data structures after initialization
  1618.      
  1619.      level 90:  detailed tracing of flow thru procedures
  1620.  
  1621.  
  1622. For optimum performance, the test of the debug level required by these
  1623. messages can be removed at compile time by not commenting out the 
  1624. `#define P4_DPRINTFL' line in the `OPTIONS' file.
  1625. (*Note Structure of the Distribution Directory::).
  1626.  
  1627. The following function is provided to deal with abnormal termination.
  1628. It can be called by any process.
  1629.  
  1630.  
  1631.      VOID p4_error(string, value)
  1632.      char *string;
  1633.      int value;
  1634.  
  1635. prints `string' as an error message and then forcefully terminates
  1636. all co-operating processes and cleans up all shared resources.
  1637.  
  1638.  
  1639.      VOID p4_soft_errors(onoff)     
  1640.      int onoff;
  1641.  
  1642. enables/disables soft errors, returning the previous setting.  The default
  1643. is "disabled", which means that certain p4 functions will call
  1644. `p4_error' instead of returning -1.
  1645.  
  1646.  
  1647. `p4_error' gets control on certain kinds of interrupts.  It is
  1648. automatically called for `SIGSEGV', `SIGBUS', and `SIGFPE'
  1649. interrupts, to catch user programming errors and clean up, after which it
  1650. returns interrupt handling to default mode and returns, so that the user
  1651. may obtain a dump.  It also handles `SIGINT' interrupts, in which case
  1652. it cleans up and exits.  Finally, it may be called directly by the user, in
  1653. which case it cleans up (other p4 processes and IPC's) and exits.
  1654.  
  1655.  
  1656. Although `p4_error' is supposed to get rid of all running p4
  1657. processes, it can happen that an error is bad enough that p4 processes
  1658. are left running.  A primitive aid in finding and killing these
  1659. processes is the shell script `kj', which takes a string as an
  1660. argument and then kills processes containing that string as part of
  1661. their program names.  Currently it only kills processes on the machine
  1662. where it is run, but it can be run via `rsh' on remote machines.
  1663. There are other useful scripts (e.g. `killipc' and `killp4')
  1664. in the `p4/bin' directory to do such things as clean up SYSV IPC 
  1665. items that may be left when a program abnormally terminates.  P4 will 
  1666. generally cleanup these items if the abnormal termination is a type that 
  1667. p4 traps, otherwise the user must do the cleanup.  This is an unfortunate
  1668. side-effect of the way that SYSV handles things, it really should be
  1669. the OS's function to take care of this.
  1670.  
  1671. On many machines it is possible to attach a debugger like `dbx' to a
  1672. running process.  This is one way to find out where a hanging process is
  1673. stuck. 
  1674.  
  1675. Miscellaneous Functions
  1676. =======================
  1677.  
  1678.  
  1679. In this section are found functions that do seem to fit neatly into any of the
  1680. other sections.
  1681.  
  1682.  
  1683.      char *p4_version()
  1684.  
  1685. returns a string containing the version number of p4 being run.
  1686.  
  1687.  
  1688.  
  1689.      VOID p4_get_cluster_masters(numids, ids)
  1690.      int *numids, ids[];
  1691.  
  1692. This procedure fills in the values of numids and ids.  It obtains the
  1693. p4-ids of all "cluster masters" for the program, placing them in the
  1694. ids array and placing the number of ids in numids.
  1695.  
  1696.  
  1697.      VOID p4_print_avail_buffs()
  1698.  
  1699. P4 maintains an array of buffer lists of various sizes, so that it can very
  1700. rapidly allocate and deallocate buffers.  You can see the contents of the
  1701. buffer pools at any time by calling this procedure.
  1702.  
  1703.  
  1704.  
  1705.      VOID p4_set_avail_buff(bufidx,size)
  1706.      int bufidx;
  1707.      int size;
  1708.  
  1709. This procedure is used to set the size of buffers in p4's buffer pools.  The
  1710. parameter `bufidx' specifies a particular buffer list, and should be a
  1711. number from 0 to 7.  The `size' parameter specifies that buffers up to
  1712. that size will be managed by p4 in a particular list.  It is important to
  1713. maintain the buffer sizes in increasing order.  The default list of buffer
  1714. sizes is {64, 256, 1024, 4096, 16384, 65536, 262144, 1048576}.  This causes
  1715. wasted space if you send only one large message, causing the allocation of a
  1716. large buffer which is not reused.  Savings in space can be achieved by
  1717. adjusting these numbers to correspond with the message sizes of your
  1718. application.  If no large messages are sent at all, however, no space is
  1719. wasted since the large buffers will never be allocated.  If you send a message
  1720. larger that the largest size in this array, p4 will allocate the buffer, and
  1721. then free it back to the system as soon as it can.
  1722.  
  1723.  
  1724.  
  1725. Fortran Interface
  1726. =================
  1727.  
  1728.  
  1729.  
  1730. The Fortran calls to p4 procedures are analogous to their C counterparts, but
  1731. have Fortran-like names.
  1732.  
  1733.      #include "p4f.h"
  1734.      
  1735.      p4init()
  1736.      p4crpg()
  1737.      p4cleanup()
  1738.      p4sendr(type,dest,msg,len,rc)
  1739.      p4sendrx(type,dest,msg,len,data_type,rc)
  1740.      p4send(type,dest,msg,len,rc)
  1741.      p4sendx(type,dest,msg,len,data_type,rc)
  1742.      p4recv(type,from,buf,buflen,msglen,rc)
  1743.      p4brdcst(type,data,len,rc)
  1744.      p4brdcstx(type,data,len,data_type,rc)
  1745.      p4probe(type,from,rc)
  1746.      p4myclid()
  1747.      p4nclids()
  1748.      p4getclids(start,end)
  1749.      p4myid()
  1750.      p4clock()
  1751.      p4ustimer()
  1752.      p4ntotids()
  1753.      p4error(str,val)
  1754.      p4softerrs(new,old)
  1755.      p4version()
  1756.      p4flush()
  1757.      p4globop(type,x,nelem,size,op,data_type,rc)
  1758.         p4intsumop()
  1759.         p4intabsmaxop()
  1760.         p4intabsminop()
  1761.         p4intmaxop()
  1762.         p4intminop()
  1763.         p4intmultop()
  1764.         p4dblsumop()
  1765.         p4dblabsmaxop()
  1766.         p4dblabsminop()
  1767.         p4dblmaxop()
  1768.         p4dblminop()
  1769.         p4dblmultop()
  1770.         p4fltsumop()
  1771.         p4fltabsmaxop()
  1772.         p4fltabsminop()
  1773.         p4fltmaxop()
  1774.         p4fltminop()
  1775.         p4fltmultop()
  1776.  
  1777.  
  1778. The `data_type' parameter in the above operations shoudl be one of
  1779. `P4INT', `P4LNG', `P4FLT', or `P4DBL'.
  1780. These symbolic constants are defined in the include file `p4f.h'.
  1781.  
  1782.  
  1783. Faster Startup with the Secure Server
  1784. =====================================
  1785.  
  1786.  
  1787.  
  1788.  
  1789.  
  1790.  
  1791. P4 processes on remote machines are ordinarily created by `rsh'.
  1792. For this to work, the user must have permission to create processes on
  1793. that machine.  This permission is normally granted either globally by
  1794. the system administrator, or locally by the use of `.rhosts' files.
  1795. (See the normal unix man pages under `rhosts').
  1796.  
  1797. Since `rsh' is relatively slow, p4 provides a way to get things
  1798. started faster.  This is accomplished by running the program
  1799. `serv_p4' in the background on the remote machine.  When p4 is
  1800. creating processes, it will automatically check for the existence of
  1801. this server and use it if it is running.  Remote processes typically
  1802. start much faster when the server is running.  A disadvantage of using
  1803. the server is that output from `p4_dprintf' is lost unless directed
  1804. by a command-line argument to a file.  (*Note Command-Line Arguments::.)
  1805. When p4 uses `rsh', the remote process's `stdout' is sent
  1806. back to the `stdout' of the parent (the p4 master process).
  1807. We have not yet tested this server on all of the machines that we support.
  1808. Thus far, we have tested it somewhat on the SYMMETRY, SUN, DEC500, and
  1809. SGI.  We believe that it will work on many other machines, but have not
  1810. yet verified it on all machines.
  1811.  
  1812. An invocation of a set of servers is (currently) associated with a specific
  1813. port number.  This way multiple users can each be running multiple server
  1814. networks without mutual interference, provided each network of servers is
  1815. started with a different port number. 
  1816.  
  1817. To start the secrue server on a machine one can do
  1818.  
  1819.      serv_p4 -d -p <num>
  1820.  
  1821.  
  1822. where `<num>' is a port number to be associated with a network of
  1823. servers.  If the `-p' option is omitted, the server will pick an unused
  1824. port number and report
  1825.  
  1826.      Listening on <num>.
  1827.  
  1828.  
  1829. Then p4 programs to use this network should be started with 
  1830.  
  1831.      -ssport <num>
  1832.  
  1833.  
  1834. The p4 application must also be listed in the user's `.p4apps' file in
  1835. his home directory.  This file should be readable only by the user, and should
  1836. contain the full path names of programs that the user wishes to be startable
  1837. by the p4 server.
  1838.  
  1839. When a p4 master process tries to start a slave process on a remote machine,
  1840. it will first attempt to do it via the server.  If it cannot do so for any
  1841. reason (no server running, port number mismatch, or program not found in
  1842. `.p4apps' file), then it tries to do so with the remote shell command.
  1843.  
  1844. Note that the server is used only to start processes; it plays no role in a p4
  1845. computation once the slave processes have been initiated.  Rather, a temporary
  1846. process, called the {listener}, is spawned to manage connection requests
  1847. that occur during the execution of a p4 program.  Neither the server nor the
  1848. listener consumes any significant amount of CPU time.
  1849.  
  1850. There is further discussion of installation options for the servers in
  1851. the `README' file in the `p4/servers' subdirectory.
  1852.  
  1853.  
  1854. Utilities for Managing a p4 Session
  1855. ===================================
  1856.  
  1857.  
  1858.  
  1859.  
  1860. A number of useful utilities can be found in the `bin' subdirectory.
  1861. These can be used to start and stop server processes based on the contents of
  1862. a file of machines one regularly uses, to kill runaway p4 processes in the
  1863. unlikely case that they cannot or do not terminate automatically when one
  1864. processes ends abnormally or interrupted from the keyboard, and to merge
  1865. logfiles created for the use of `upshot' *Note Creating Logfiles for Upshot::. 
  1866.  
  1867.  
  1868. Creating Logfiles for Upshot
  1869. ============================
  1870.  
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876. P4 is distributed with a set of routines for creating logfiles (see
  1877. `README' in the `p4/alog' directory.  The resulting logfiles
  1878. can be examined by `upshot', distributed separately.  For details
  1879. about `upshot', see [herrarte-lusk:upshot].  
  1880.  
  1881. The `p4/alog' directory contains a package (ALOG) for creating logs of
  1882. time-stamped events, that is of general utility, outside of p4.  The
  1883. timestamps are obtained from various microsecond-level resolution timers on
  1884. various machines.  The portable microsecond timing package is contained in the
  1885. `usc' subdirectory.  It is used by the ALOG package as well as by the
  1886. `p4_ustimer' function in p4.  Similarly, the ALOG package can be used
  1887. independently of p4 and `upshot'. Its logfiles were designed to be read
  1888. and displayed by upshot, but other display packages can be used as well.
  1889.  
  1890.  
  1891.  
  1892. User-Specified Events
  1893. ---------------------
  1894.  
  1895.  
  1896.  
  1897. The ALOG package consists of a set of macros that can be used to instrument a
  1898. C program and a set of functions that can be used to instrument a Fortran
  1899. program.  We will focus here primarily on the use of the C interface, which
  1900. contains more functionality.
  1901.  
  1902. The macros that can be used to instrument a program are as follows (from the 
  1903. file `README_ALOG' in the `alog' directory):
  1904.  
  1905.  
  1906.      ALOG_SETUP(pid,flag):    
  1907.        pid  -  (integer) process id of callee
  1908.        flag -  (integer) either ALOG_WRAP or ALOG_TRUNCATE  
  1909.  
  1910. This macro initializes the tracing area for a slave process and must be called
  1911. once before any event is logged.  If the value of `flag' is set to
  1912. `ALOG_WRAP', then in the event of no more space for logging events the
  1913. system will only report the latest n events.  If `flag' is set to
  1914. `ALOG_TRUNCATE' the system will stop logging events as soon as there is
  1915. no more memory for the events to be logged.
  1916.  
  1917.  
  1918.      ALOG_MASTER(pid,flag):
  1919.        pid  -  (integer) process id of the callee
  1920.        flag -  (integer) either 0 or 1  (see above)
  1921.  
  1922. `ALOG_SETUP' with the difference that this macro should be referenced by
  1923. the master process only.
  1924.  
  1925.  
  1926.      ALOG_DEFINE(event,strdef,format):
  1927.        event  - (integer) id of event being defined
  1928.        strdef - (string) description of 'event'
  1929.        format - (string) control string in "printf" format to
  1930.  
  1931. This macro puts an event definition code into the logfile.
  1932.  
  1933.  
  1934.      ALOG_LOG(pid,event,intdata,strdata):
  1935.        pid     - (integer) process id of callee
  1936.        event   - (integer) event id to be logged
  1937.        intdata - (integer) any integer data for this event
  1938.        strdata - (string) any string data (can be the null string)
  1939.  
  1940. This macro provides the event logging service.
  1941.  
  1942.  
  1943.      ALOG_OUTPUT
  1944.        no parameters  
  1945.  
  1946. This macro dumps the events logged into a log file with the name
  1947. `alogfile.pxx' where `xx' is the logical PID of the callee process.
  1948. The log file is created in the current directory unless specified otherwise
  1949. through the macro ALOG_SETDIR.
  1950.  
  1951.  
  1952.      ALOG_SETDIR(dir)
  1953.        dir - (string) directory where log file is created
  1954.  
  1955. This macro sets the output directory for the log file.  The default directory
  1956. for the creation of the log file is the current directory of the process.  If
  1957. used, then this macro MUST be invoked before `ALOG_MASTER/ALOG_SETUP'.
  1958.  
  1959.  
  1960.      ALOG_STATUS(status):
  1961.        status - (integer) either ALOG_ON or ALOG_OFF
  1962.  
  1963.  
  1964. This macro controls the logging status of `ALOG' as follows.  Setting
  1965. `status' to `ALOG_ON' enables logging until it is turned off.
  1966. Setting `status' to `ALOG_OFF' disables logging until it is turned
  1967. on again.  Logging is enabled at the outset by default.
  1968.  
  1969.  
  1970.  
  1971.      ALOG_ENABLE
  1972.        no parameters
  1973.  
  1974.  
  1975. This macro enables event logging; same as calling `ALOG_STATUS(ALOG_ON)'.
  1976.  
  1977.  
  1978.      ALOG_DISABLE
  1979.        no parameters
  1980.  
  1981. This macro disables event logging; same as calling
  1982. `ALOG_STATUS(ALOG_OFF)'.
  1983.  
  1984. The sample program `gridlog.shmem.c' in the `monitors' subdirectory
  1985. contains an example of a program instrumented with ALOG statements.  The macro
  1986. definitions for ALOG are included when you include `#include "p4"' in
  1987. your program.  If the line `#define ALOG_TRACE' is not included before
  1988. the `#include "p4"', these macros will generate no code.  Thus it is
  1989. easy to effectively de-instrument the code by recompiling, and there is no
  1990. need to protect each ALOG statement with an `#ifdef'.
  1991.  
  1992. When an ALOG-instrumented program is run, it will produce one logfile for each
  1993. process.  The files will be named `alogfile.p0', `alogfile.p1',
  1994. .  These files need to be merged into a single file with the events
  1995. sored by timestamp.  This is accomplished with the program `mergelogs',
  1996. found in the `bin' subdirectory.  To merge the logfiles, do 
  1997.  
  1998.      mergelogs alogfile.p* > myprog.log
  1999.      rm alogfile.p*
  2000.  
  2001.  
  2002. The resulting logfile can be examined by upshot or some other logfile
  2003. examination facility.  See [herrarte-lusk:upshot] for details of the
  2004. logfile format.
  2005.  
  2006. On networks of workstations and some distributed memory machisnes, the
  2007. microsecond timers on the various processors are synchronized.  To produce a
  2008. usable merged logfile, the `adjlogs' program, also found in the
  2009. `bin' directory, can be used to adjust the timestamps for offset and
  2010. drift before they are merged.  For this to work, synchronization events must
  2011. be placed in the logfiles by an `ALOG_LOG' statement.  The event type
  2012. is then passed to `adjlogs', which aligns the timestamps, based on the
  2013. timestamps of the synchonization events.  The call to `adjlogs' looks
  2014. like this, where `<n>' is the type of the synchronization event.
  2015.  
  2016.      adjlogs -e <n>
  2017.  
  2018.  
  2019. Both `mergelogs' and `adjlogs' are less portable than the other p4
  2020. code;  you might want to run them on a workstation such as a Sun.
  2021.  
  2022.  
  2023. Examining Log Files with Upshot
  2024. -------------------------------
  2025.  
  2026.  
  2027.  
  2028.  
  2029. `Upshot' is not part of the p4 distribution, but can be obtained from the
  2030. same anonymous `ftp' location as p4.  Take the file `upshot.tar.Z'
  2031. from the directory `pub/p4' on `info.mcs.anl.gov'.  The distribution
  2032. contains all necessary documentation on how to install and run `upshot'.
  2033. It is an X-window program that runs on most workstations.  There is no need
  2034. for a parallel macchine to be involved, once the log files have been obtained.
  2035.  
  2036. `Upshot' produces the most interesting displays when certain events
  2037. (not necessarily all) are defined to be the entry and exit events for certain
  2038. {states} and then colors are associated with the states.  This association
  2039. is reflected in a {statefile} with a format like the following:
  2040.  
  2041.      1 1 2 red   asking
  2042.      2 3 4 blue  working
  2043.      3 5 6 green updating
  2044.  
  2045.  
  2046. This statefile describes three states.  State 1 is defined to be between
  2047. events 1 and 2.  `Upshot' will color it red and label it "asking".
  2048.  
  2049.  
  2050. Automatic Logging of p4 Events
  2051. ------------------------------
  2052.  
  2053.  
  2054.  
  2055. We have found that the most useful events to log and study are those
  2056. identified by the user and specified in his program.  That way he can control
  2057. the number of events to be logged and the grain size of the states that are
  2058. represented.  
  2059.  
  2060. In some cases, however, one wants to study the details of the internal
  2061. operation of a p4 application, or get some idea of the behavior on one's
  2062. program without going to the trouble of instrumenting it himself.  To this
  2063. end, p4 itself is instrumented with ALOG statements, although by default they
  2064. are inactive.  To get automatic logging of p4 events (including sending and
  2065. receiving of each message) one needs first to link to a version of the p4
  2066. library that has been compiled with the line `#define ALOG_TRACE'
  2067. uncommented out in the `OPTIONS' file, and secondly, to run with
  2068. `-p4log' on the command line.
  2069.  
  2070.  
  2071.  
  2072. Machine-Specific Notes
  2073. ======================
  2074.  
  2075.  
  2076.      SUN
  2077.          (1)  P4 can be installed on this machine with or without SYSV IPC.
  2078.      
  2079.      HP
  2080.          (1)  P4 can be installed on this machine with or without SYSV IPC.
  2081.          (2)  Fortran not tested (not avail on our test machine).
  2082.      
  2083.      DEC5000
  2084.          (1)  P4 can be installed on this machine with or without SYSV IPC.
  2085.      
  2086.      RS6000
  2087.          (1)  P4 can be installed on this machine with or without SYSV IPC.
  2088.      
  2089.      IBM3090
  2090.          (1)  P4 can be installed on this machine with or without SYSV IPC.
  2091.          (2)  Fortran not supported due to absence of iargc/getarg.
  2092.          (3)  There are multiply defined macros in include/rpc/rpc.h.  IBM
  2093.               is fixing this in a later OS release.  Meanwhile make your own
  2094.               copy and the fix the problem yourself.
  2095.          
  2096.      TITAN
  2097.          (1)  P4 can be installed on this machine with or without SYSV IPC.
  2098.          (2)  Fortran not supported due to problems with getting args.
  2099.      
  2100.      SGI
  2101.          (1)  P4 can be installed on this machine with or without SYSV IPC.
  2102.      
  2103.      NEXT
  2104.          (1)  Fortran not supported due to absence of iargc/getarg.
  2105.      
  2106.      FX2800/FX2800_SWITCH
  2107.          (1)  Alliant's switch code not yet ensuring messages 
  2108.               remain ordered.  p4 currently discovers the switch port for
  2109.               the machine it is running on by invoking the internal
  2110.               procedure getswport.  This procedure must be customized to
  2111.               the installation.
  2112.            
  2113.      FX8
  2114.          (1)  You might need to add MFLAGS = -i to the Makefile
  2115.      
  2116.      KSR
  2117.          (1)  The latest version of the OS produces a link-time error for
  2118.               Fortran programs.
  2119.      
  2120.      IPSC860
  2121.          (1)  the script "runcube" (in the messages directory) may 
  2122.               be useful
  2123.           
  2124.      DELTA
  2125.          (1)  the script "rundelta" (in the messages directory) may 
  2126.               be useful
  2127.      
  2128.      BALANCE
  2129.          (1)  Fortran not supported.
  2130.      
  2131.      SYMMETRY/SYMMETRY_PTX
  2132.          (1)  -Z compiler option may be used to control shmalloc/malloc split
  2133.          (2)  shared memory message passing not supported in Fortran
  2134.      
  2135.      TC_2000/TC_2000_TCMP
  2136.          (1)  TCMP port not yet complete.
  2137.          (2)  For shared-memory execution, one must use `cluster ...' to
  2138.               obtain a private cluster for execution
  2139.  
  2140.  
  2141.  
  2142.  
  2143. Some Common Problems and their Solutions
  2144. ========================================
  2145.  
  2146.  
  2147.  
  2148.  
  2149. Our attempt with this manual has been to prevent you from having difficulties.
  2150. Experience shows that certain common progblems recur, however.  In this
  2151. section we hope to address some of these problems.
  2152.  
  2153. "Permission Denied."     
  2154.       p4 slave processes are started by forks (for
  2155.        slaves in the same shared-memory cluster), by the server, or by the remote
  2156.        shell command.  If the server is running on the target machine then that
  2157.        must be configured to allow remote processes to be started.  To test whether
  2158.        this is your problem, try
  2159.               rsh target.machine date
  2160.      
  2161.        If you still get the "Permission denied." message, then the problem has
  2162.        nothing to do with p4.  See `hosts.equiv' or `.rhosts' in the
  2163.        system man pages.
  2164. "More processes than message queues"     
  2165.        Under the default configuration
  2166.        of p4, uniprocessors, such as most workstations, cannot have multiple
  2167.        process sharing memory.  Thus your procgroup file for a workstation network
  2168.        should always look like
  2169.               local 0
  2170.               machine1 1 pathname
  2171.               machine2 1 pathname
  2172.               machine3 1 pathname
  2173.                  .
  2174.                  .
  2175.      
  2176.        The "local" means "only the master on the startup machine; no local
  2177.        slaves sharing memory".
  2178.      
  2179.      
  2180.        It is possible, at some cost in message-passing efficiency, to have a
  2181.        cluster of processes sharing memory on a workstation, but in this case p4
  2182.        must have been installed with the `SYSV_IPC' option set in the
  2183.        `OPTIONS' file.  The cost is that a process waiting for a message must
  2184.        spin between checking for a message arriving on a socket and a message
  2185.        arriving through shared memory. 
  2186.      
  2187. "p4error: local is not first entry in procgroup"     
  2188.        the first line of
  2189.        the procgroup file must be the "local" entry, specifying the number of
  2190.        slaves that will be run on the master machine in addition to the master
  2191.        process. 
  2192.      
  2193. "gethostbyname failed 100 times"     
  2194.       Check for an invalid machine name in
  2195.        the procgroup file.
  2196. "pgmpathname: Command not found"     
  2197.        P4 tried to start the program
  2198.        with the given name on a remote machine and the program did not exist.
  2199.        Verify the full path name of the program.
  2200. program hangs     
  2201.        You may have failed to initialize the `type' and
  2202.        `from' fields before a `p4_recv'.  You might have used
  2203.        `p4_sendr' between two processes at the same time, which will deadlock
  2204.        if you think about it, or even if you don't.  Use `p4_send' instead.
  2205. program hangs or has bad data in received message     
  2206.        You might have
  2207.        failed to set the pointer to the incoming buffer to NULL, or to have
  2208.        specifically allocated a buffer with `p4_msg_alloc', before a
  2209.        `p4_recv'.
  2210. program ignores command-line arguments     
  2211.        You might have passed
  2212.        `argc' instead of `&argc' to `p4_initenv'.
  2213. program runs out of memory     
  2214.        You may need to call `p4_msg_free'
  2215.        after each `p4_recv', or reuse buffers by pre-allocating them.
  2216.      
  2217.      
  2218.  
  2219.